package com.peng.rpc.loadBalance;

import com.alibaba.nacos.api.naming.pojo.Instance;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Wonderson
 * @email wpp.ds@foxmail.com
 * @date 2022/3/7 21:38
 */
public class RoundRobinLoadBalance implements LoadBalance{

    private static final AtomicInteger IDX = new AtomicInteger(0);

    @Override
    public Instance select(List<Instance> instances) {
        return instances.get(IDX.getAndIncrement() % instances.size());
    }
}
